package com.dyz.leetcode;

import java.util.Arrays;

public class LeastInterval621 {
    public int leastInterval(char[] tasks, int n) {
        int[] record = new int[26]; //26个字母
        for(char a: tasks){
            record[a-'A']++;
        }
        Arrays.sort(record);
        int max_n = record[25]-1;
        int space=max_n*n;//休息空间
        for(int i=24;i>=0&& record[i]>0;i--){
            space -= Math.min(max_n, record[i]);
        }
        return space >0? tasks.length+space:tasks.length;
    }
}
